package fr.gestproj.model.dto;

import javax.faces.component.html.HtmlOutputText;

import org.primefaces.component.column.Column;

import fr.gestproj.utils.UtilsJsf;

public class DTOColumnModel {

	private String header;
	private String champ;
	private boolean sortable;
	private boolean filterable;
	private Class classe;
	private Column column;

	public DTOColumnModel() {
	}

	public DTOColumnModel(String header, String champ, boolean sortable, boolean filterable, Class classe) {
		super();
		this.header = header;
		this.champ = champ;
		this.sortable = sortable;
		this.filterable = filterable;
		this.classe = classe;
	}

	public String getHeader() {
		return header;
	}

	public void setHeader(String header) {
		this.header = header;
	}

	public String getChamp() {
		return champ;
	}

	public void setChamp(String champ) {
		this.champ = champ;
	}

	public boolean isSortable() {
		return sortable;
	}

	public void setSortable(boolean sortable) {
		this.sortable = sortable;
	}

	public boolean isFilterable() {
		return filterable;
	}

	public void setFilterable(boolean filterable) {
		this.filterable = filterable;
	}

	public Class getClasse() {
		return classe;
	}

	public void setClasse(Class classe) {
		this.classe = classe;
	}

	@SuppressWarnings("el-syntax")
	public Column getPrimefacesColumn() {
		column = new Column();
		HtmlOutputText outputHeader = new HtmlOutputText();
		outputHeader.setValue(getHeader());
		column.getFacets().put("header", outputHeader);
		if (isSortable()) {
			column.setValueExpression("sortBy", UtilsJsf.evaluate(String.format("#{%s}", getChamp())));
		}
		if (isFilterable()) {
			column.setValueExpression("filterBy", UtilsJsf.evaluate(String.format("#{%s}", getChamp())));
		}
		return column;
	}

	public void setPrimefacesColumn(Column column) {
		this.column = column;
	}

}
